package net.baipeng.bp_aliyun_push;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import com.alibaba.sdk.android.push.AndroidPopupActivity;

import java.util.Map;

import io.flutter.Log;

public class PopupPushActivity extends AndroidPopupActivity {
    static final String TAG = "BpAliyunPushPlugin PopupPushActivity";

    private Handler handler = new Handler(Looper.getMainLooper());

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        Window window = getWindow();
//        window.setGravity(Gravity.LEFT | Gravity.TOP);
//        WindowManager.LayoutParams params = window.getAttributes();
//        params.x = 0;
//        params.y = 0;
//        params.height = 1;
//        params.width = 1;
//        window.setAttributes(params);
    }

    @Override
    protected void onSysNoticeOpened(String title, String summary, Map<String, String> extMap) {
        Log.i(TAG, "OnMiPushSysNoticeOpened, title: " + title + ", content: " + summary + ", extMap: " + extMap);

        final FlutterPushNotification notification = new FlutterPushNotification();
        notification.title = title;
        notification.summary = summary;
        notification.extraMap = extMap.toString();
        BpAliyunPushPlugin.launchNotification = notification;

        Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
        startActivity(intent);
        finish();
        
        /*
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                BpAliyunPushPlugin.sendPushNotification(notification);

                finish();
            }
        }, 1500);
         */
    }
}

